<!DOCTYPE html>
<html>

<head>
    <title>导航页</title>
    <style>
        a {
            text-decoration: none;
        }

        a,
        body {
            color: #34495e;
        }

        li {
            display: list-item;
            list-style-type: none;
            text-align: -webkit-match-parent;
        }

        .news-list,

        .news-list-nav {
            padding: 15px 30px;
            position: fixed;
            text-align: center;
            top: 55px;
            left: 0;
            right: 0;
            z-index: 698;
            box-shadow: 0 1px 2px rgba(0, 0, 0, .1)
        }

        .news-list-nav .disabled {
            color: #ccc
        }

        .news-list {
            position: absolute;
            margin: 30px 0;
            width: 80%;
            transition: all .5s cubic-bezier(.55, 0, .1, 1)
        }

        .news-list ul {
            list-style-type: none;
            padding: 0;
            margin: 0
        }

        .news-item {
            background-color: #fff;
            padding: 20px 30px 20px 80px;
            border-bottom: 1px solid #eee;
            position: relative;
            line-height: 20px
        }

        .news-item .score {
            color: #f60;
            font-size: 1.1em;
            font-weight: 700;
            position: absolute;
            top: 50%;
            left: 0;
            width: 80px;
            text-align: center;
            margin-top: -10px
        }

        .news-item .host,
        .news-item .meta {
            font-size: .85em;
            color: #828282
        }

        .news-item .host a,
        .news-item .meta a {
            color: #828282;
            text-decoration: underline
        }

        .news-item .host a:hover,
        .news-item .meta a:hover {
            color: #f60
        }
    </style>
</head>

<body background-color=#f2f3f5>
    <div class="news-view view">
        <div class="news-list" id="news-list">
            <ul>
                <li class="news-item">
                    <span class="score">01</span>
                    <span class="title">
                        <a href="https://xiexiaopeng2002.github.io/SNC-2022-summertutorial/考核期作业/斐波那契数列计算器.html"
                            target="_blank" rel="noopener" id="1">正在加载</a>
                        <span class="host"> 考核期作业</span>
                    </span>
                    <br>
                    <span class="meta">
                        <span class="by">
                            by
                            <a href="/user/Raphael_Amiard" class="">xiexiaopeng</a>
                        </span>
                        <span class="time">
                            2022/07/01
                        </span>
                        <span class="comments-link">
                            <a href="/item/31975507" class="">16 comments</a>
                        </span>
                    </span>
                </li>
                <li class="news-item">
                    <span class="score">01</span>
                    <span class="title">
                        <a href="https://xiexiaopeng2002.github.io/SNC-2022-summertutorial/考核期作业/斐波那契数列计算器.html"
                            target="_blank" rel="noopener" id="2">正在加载</a>
                        <span class="host"> 考核期作业</span>
                    </span>
                    <br>
                    <span class="meta">
                        <span class="by">
                            by
                            <a href="/user/Raphael_Amiard" class="">xiexiaopeng</a>
                        </span>
                        <span class="time">
                            2022/07/01
                        </span>
                        <span class="comments-link">
                            <a href="/item/31975507" class="">16 comments</a>
                        </span>
                    </span>
                </li>
                <li class="news-item">
                    <span class="score">01</span>
                    <span class="title">
                        <a href="https://xiexiaopeng2002.github.io/SNC-2022-summertutorial/考核期作业/斐波那契数列计算器.html"
                            target="_blank" rel="noopener" id="3">正在加载</a>
                        <span class="host"> 考核期作业</span>
                    </span>
                    <br>
                    <span class="meta">
                        <span class="by">
                            by
                            <a href="/user/Raphael_Amiard" class="">xiexiaopeng</a>
                        </span>
                        <span class="time">
                            2022/07/01
                        </span>
                        <span class="comments-link">
                            <a href="/item/31975507" class="">16 comments</a>
                        </span>
                    </span>
                </li>
                <li class="news-item">
                    <span class="score">01</span>
                    <span class="title">
                        <a href="https://xiexiaopeng2002.github.io/SNC-2022-summertutorial/考核期作业/斐波那契数列计算器.html"
                            target="_blank" rel="noopener" id="4">正在加载</a>
                        <span class="host"> 考核期作业</span>
                    </span>
                    <br>
                    <span class="meta">
                        <span class="by">
                            by
                            <a href="/user/Raphael_Amiard" class="">xiexiaopeng</a>
                        </span>
                        <span class="time">
                            2022/07/01
                        </span>
                        <span class="comments-link">
                            <a href="/item/31975507" class="">16 comments</a>
                        </span>
                    </span>
                </li>
                <li class="news-item">
                    <span class="score">01</span>
                    <span class="title">
                        <a href="https://xiexiaopeng2002.github.io/SNC-2022-summertutorial/考核期作业/斐波那契数列计算器.html"
                            target="_blank" rel="noopener" id="5">正在加载</a>
                        <span class="host"> 考核期作业</span>
                    </span>
                    <br>
                    <span class="meta">
                        <span class="by">
                            by
                            <a href="/user/Raphael_Amiard" class="">xiexiaopeng</a>
                        </span>
                        <span class="time">
                            2022/07/01
                        </span>
                        <span class="comments-link">
                            <a href="/item/31975507" class="">16 comments</a>
                        </span>
                    </span>
                </li>
            </ul>
        </div>
    </div>
    <script type="module">
        const newsList = document.getElementById("news-list")
        const basicURL = "https://hacker-news.firebaseio.com/v0/";
        const tops = await fetch(`${basicURL}topstories.json?print=pretty`).then(res => res.json());
        const list = tops.slice(0, 10)
        var x = 1
        var m = 0;
        function timeago(m) {
            var n;
            if (m < 60) {
                n = `${m}分钟前`;
                return n;
            }
            else {
                m = parseInt(m / 60);
                n = `${m}小时前`;
                return n;
            }
        }
        for (const itemID of list) {
            const post = await fetch(`${basicURL}item/${itemID}.json?print=pretty`).then(res => res.json());
            const a = document.getElementById(`${x}`)
            a.innerText = post.title
            a.href = post.url
            m = parseInt((Math.round(new Date() / 1000) - post.time) / 60)
            document.getElementsByClassName("score")[x - 1].innerText = post.score
            document.getElementsByClassName("comments-link")[x - 1].children[0].innerText = `${post.kids.length} comments`
            document.getElementsByClassName("time")[x - 1].innerText = timeago(m)
            document.getElementsByClassName("by")[x - 1].children[0].innerText = post.by
            document.getElementsByClassName("host")[x - 1].innerText = /(www\.){0}[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b/.exec(post.url)
            //newsList.replaceChild(a)
            x = x + 1
        }
    </script>
</body>

</html>